package algorithm.sort;

public class Insert {
    public void insertSort(Comparable[] arr) {
        for (int i =1 ;i<arr.length;i++){
            for (int j =i;j>=0;j--) {
                if (greater(arr[j-1],arr[j])){
                    swap(arr,j-1,j);
                }else {
                    break;
                }
            }
        }
    }

    private boolean greater(Comparable v, Comparable w){
        return v.compareTo(w)>0;
    }

    private void swap(Comparable[] arr, int i, int j){
        Comparable tmp = arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }
}
